import sqlite3

conn = sqlite3.connect('./db/src/set.db')

print("Opened database successfully")

c = conn.cursor()
# 创建用户表
c.execute('''CREATE TABLE user
       (id INTEGER PRIMARY KEY  NOT NULL,
       loginname           TEXT    NOT NULL,
       username            TEXT     NOT NULL,
       password            TEXT     NOT NULL,
       update_time         TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')));''')

# 新建默认用户
c.execute("INSERT INTO user (loginname,username,password) VALUES ( 'admin', '超级管理员', 'admin');")
print("Table created successfully")

# 创建token表
c.execute('''CREATE TABLE token
       (token           TEXT    NOT NULL,
       loginname        TEXT     NOT NULL,
       ip               TEXT     NOT NULL,
       update_time      TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')));''')

conn.commit()
conn.close()
